package com.xsl.lession02.controller;

import cn.hutool.core.map.MapUtil;
import com.xsl.lession02.service.RouteService;
import com.xsl.lession02.vo.ErrorResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * 路线相关的业务
 */
@RestController
@RequestMapping("route")
public class RouteController {

    @Autowired
    private RouteService routeService;

    /**
     * 创建路线
     *
     * @return
     */
    @PostMapping
    public Object createRoute(@RequestParam("userId") Long userId) {
        String routeId = this.routeService.createRoute(userId);
        if (null != routeId) {
            //创建成功
            return MapUtil.builder("routeId", routeId).build();
        }
        //创建失败
        return ErrorResult.builder()
                .errCode("500")
                .errMessage("创建路线失败！").build();
    }

}
